<html>
<head>
<title>Intro to Java Programming, 6E - null</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<style type = "text/css">
body {font-family: "Courier New", sans-serif; font-size: 100%; color: black}
.keyword {color: #000080; font-weight: bold}
.comment {color: #008000}
.literal {color: #0000ff}
</style>
</head>
<body>
<pre>
<span class = "keyword">package</span> ch14;

<span class = "keyword">import</span> java.util.Random;
<span class = "keyword">import</span> javafx.application.Application;
<span class = "keyword">import</span> javafx.stage.Stage;
<span class = "keyword">import</span> javafx.scene.layout.*;
<span class = "keyword">import</span> javafx.scene.*;
<span class = "keyword">import</span> javafx.scene.control.Button;
<span class = "keyword">import</span> javafx.scene.image.*;
<span class = "keyword">import</span> javafx.geometry.*;

<span class = "keyword">public</span> <span class = "keyword">class</span> Cards <span class = "keyword">extends</span> Application {
    <span class = "keyword">public</span> <span class = "keyword">static</span> <span class = "keyword">void</span> main(String[] args) {
        launch(args);
    }

    <span class = "keyword">public</span> <span class = "keyword">void</span> start(Stage primaryStage) <span class = "keyword">throws</span> Exception {
        CardPane pane = <span class = "keyword">new</span> CardPane();
        Scene scene = <span class = "keyword">new</span> Scene(pane);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

<span class = "keyword">class</span> CardPane <span class = "keyword">extends</span> BorderPane {
    GridPane pane = <span class = "keyword">new</span> GridPane();
    Button button = <span class = "keyword">new</span> Button(<span class = "literal">"random"</span>);

    <span class = "keyword">public</span> CardPane() {
        PutCards(<span class = "literal">1</span>, <span class = "literal">2</span>, <span class = "literal">3</span>, <span class = "literal">4</span>);
        Random random = <span class = "keyword">new</span> Random();
        button.setOnMousePressed(e -&gt; PutCards(random.nextInt(<span class = "literal">54</span>) + <span class = "literal">1</span>, random.nextInt(<span class = "literal">54</span>) + <span class = "literal">1</span>, random.nextInt(<span class = "literal">54</span>) + <span class = "literal">1</span>,
                random.nextInt(<span class = "literal">54</span>) + <span class = "literal">1</span>));
    }

    <span class = "keyword">void</span> PutCards(<span class = "keyword">int</span> a, <span class = "keyword">int</span> b, <span class = "keyword">int</span> c, <span class = "keyword">int</span> d) {
        getChildren().clear();
        ImageView imageView1 = <span class = "keyword">new</span> ImageView(<span class = "keyword">new</span> Image(<span class = "literal">"image/card/"</span> + a + <span class = "literal">".png"</span>, <span class = "literal">72</span>, <span class = "literal">96</span>, <span class = "keyword">false</span>, <span class = "keyword">false</span>));
        ImageView imageView2 = <span class = "keyword">new</span> ImageView(<span class = "keyword">new</span> Image(<span class = "literal">"image/card/"</span> + b + <span class = "literal">".png"</span>, <span class = "literal">72</span>, <span class = "literal">96</span>, <span class = "keyword">false</span>, <span class = "keyword">false</span>));
        ImageView imageView3 = <span class = "keyword">new</span> ImageView(<span class = "keyword">new</span> Image(<span class = "literal">"image/card/"</span> + c + <span class = "literal">".png"</span>, <span class = "literal">72</span>, <span class = "literal">96</span>, <span class = "keyword">false</span>, <span class = "keyword">false</span>));
        ImageView imageView4 = <span class = "keyword">new</span> ImageView(<span class = "keyword">new</span> Image(<span class = "literal">"image/card/"</span> + d + <span class = "literal">".png"</span>, <span class = "literal">72</span>, <span class = "literal">96</span>, <span class = "keyword">false</span>, <span class = "keyword">false</span>));
        pane.add(imageView1, <span class = "literal">0</span>, <span class = "literal">0</span>);
        pane.add(imageView2, <span class = "literal">1</span>, <span class = "literal">0</span>);
        pane.add(imageView3, <span class = "literal">2</span>, <span class = "literal">0</span>);
        pane.add(imageView4, <span class = "literal">3</span>, <span class = "literal">0</span>);
        setCenter(pane);
        setBottom(button);
        setAlignment(button, Pos.BOTTOM_CENTER);
    }
}
</pre>
</body>
</html>
